<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML >
<html>
<head>
<base href="<%=basePath%>">

<title>班级资料</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<%@include file="/pages/head/head.jsp"%>
<style type="text/css">
.tdcenter{
text-align: center;
vertical-align: middle;
}
</style>
</head>
<body>
	<div id="wrapper">
		<!-- 左边菜单 -->
		<%@include file="/pages/left/leftmenu.jsp"%>

		<div id="page-wrapper" class="gray-bg dashbard-1">
			<!-- 引入top菜单 -->
			<%@include file="/pages/left/topmenu.jsp"%>

			<!--左边内容开发，开始  -->
			<div class="row wrapper border-bottom white-bg page-heading">
				<div class="col-lg-10">
					<h2>班级资料</h2>
					<ol class="breadcrumb">
						<li><a href="index.html">主页</a></li>
						<li><a>班级资料</a></li>
						<li><strong>添加班级资料</strong></li>
					</ol>
				</div>
				<div class="col-lg-2"></div>
			</div>
			<div class="wrapper wrapper-content animated fadeInRight">

				<div class="row">
					<div class="col-lg-14">
						<div class="ibox float-e-margins">
							<div class="ibox-title">
								<h5>添加班级资料</h5>
								<div class="ibox-tools">
									<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
									</a>
								</div>
							</div>
							<div class="ibox-content">
							 <div class="table table-bordered ">
								<table width="100%" class="tabStyle table table-bordered" style="margin-bottom: 0;  ">
								<tr >
								<td style="text-align: center;vertical-align: middle;" width="8%">搜索条件</td>
								<td style="text-align: center;vertical-align: middle;" width="8%">班级编号</td>
								<td><input class="form-control" id="classCode" name="classCode"> </td>
								<td style="text-align: center;vertical-align: middle;" width="5%">班级名称</td>
								<td><input class="form-control" id="className" name="className" > </td>
								<td> <button class="btn btn-primary"  type="button" onclick="queryclass()">查询</button></td>
								</tr>
								
								</table>
                               </div> 
                            
								<div class="table table-bordered">
								<table id="tabelid" width="100%" class="tabStyle tabStyle1 table table-bordered" style="margin-bottom: 0">
									<tr>
										<th width="4%">序号</th>
										<th width="18%">班级编号</th>
										<th width="20%">班级名称</th>
										<th width="20%">学年</th>
										<th width="10%">操作</th>
									</tr>

								</table>
								<div style="float: left;">
									共<strong id="total"></strong>条记录
								</div>
								<div id="pager" style="float: right;"></div>
							</div>
							</div>
							

						</div>
					</div>
				</div>
<input type="hidden" id="__page" name="page" value="1"/>

			</div>
		
		</div>
	</div>
	<%@include file="/pages/head/foot.jsp"%>

	<script>
	
/*   	  $(document).ready(function() {
		  var flag = true;
		  $('#allcheck').click(function() {
		    	if ($('#allcheck').attr('checked') != 'checked') {
		     		if(flag){
		     			$("input[type='checkbox']").prop("checked", true);
		     			flag = false;
		     		}else{
		     			$("input[type='checkbox']").prop("checked", false);
		     			flag = true;
		     		}
		     	}
		     });
	  }); */
 	  
 	/*  
 	 $(document).ready(function() {

 	      $('#allcheck').click(function() {
 	    	 if ($("#allcheck").attr("checked")) {
 	    		            $(":checkbox").attr("checked", true);
 	    		        } else {
 	    		            $(":checkbox").attr("checked", false);
 	    		        }
 	          	
 	          });
 	      
 			});
	  */
/* 	  $(function(){
			//date
		  $('#allcheck').click(function() {
		    	if ($('#allcheck').attr('checked') == 'checked') {
		     		$("input[type='checkbox']").prop("checked", true);
		     	}  
		    	if ($('#allcheck').attr('checked') != 'checked') {
		     			$("input[type='checkbox']").prop("checked", false);
		     		}
		     		
		    	
		     });
		});  */
	  
	/*   $(document).ready(function() {
		  $('#allcheck').click(function() {
			  if ($('#allcheck').attr('checked') != 'checked') {
				  alert($('#allcheck').attr('checked'));
	     			$("input[type='checkbox']").prop("checked", true);
	     			alert($('#checkb1').attr('checked'));
	     	}
		    	if ($('#allcheck').attr('checked') == 'checked') {
		     		$("input[type='checkbox']").prop("checked", false);
		     	}
		     });
	  }); */
	  var pageCurrent = 1;
	
	$(function(){
		//date
        $('.input-group.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });
	});
		function PageClick(pageclickednumber) {
			pageCurrent = pageclickednumber;
			
			var classcodecopy = "";
			var classnamecopy = "";
			$("#__page").val(pageclickednumber);
			
			if($("#classCode").val() != ""){
				classcodecopy = $("classCode").val();
			}
			if($("#className").val() !=""){
				classnamecopy = $("className").val();
			}
			var url = "${pageContext.request.contextPath}/classrequire/queryClassrequire.do";
			 var param = {"page" : pageclickednumber,"classCode":$("#classCode").val(),"className":$("#className").val(),"years":$("#years").val()}; 
			$.post(url,param,function(data) {
								$('.tabStyle1 tr:not(:first)').remove();
								for ( var i in data) {
									pageCount = data[i].pageCount;
									if (pageCount > 0) {
										$("#total").text(data[i].total);
										$("#pager").pager({pagenumber : pageclickednumber,pagecount : pageCount,buttonClickCallback : PageClick
										});
										var datas = data[i].rows;
										for ( var j in datas) {
											if (j == "remove") {
												return;
											}
											var tr = $("<tr></tr>");
											var jj = parseInt(j) + 1;
											var mindex = (jj < 10 ? "0" + (jj): jj);
											$("<td></td>").append(mindex).appendTo($(tr));
											$("<td></td>").append(datas[j].classCode).appendTo($(tr));
											$("<td></td>").append(datas[j].className).appendTo($(tr));
											$("<td></td>").append(datas[j].years).appendTo($(tr));
											 var no_id = datas[j].classId;
											var html = "<a href='${pageContext.request.contextPath}/classrequire/toUpdateClassrequire.do?classId="+ no_id+"'>编辑</a>｜<a href='${pageContext.request.contextPath}/classrequire/deleteClassrequire.do?classId="+ no_id+ "&pageCounts= "+pageclickednumber+"' onclick=\"return deleteModel();\">删除</a>";
        								
											$("<td></td>").append(html).appendTo($(tr)); 
											$(tr).appendTo($("#tabelid"));
											$("#tabelid tr:odd").addClass("bgWhite");
										}
									} else if (typeof (data[i].rows) == 'undefined') {
										window.location.reload();
									}
									var len = data[i].rows.length;

									if (len == 0) {
										$("#total").text(0);
										$("#pager").pager({
											pagenumber : pageclickednumber,
											pagecount : 0,
											buttonClickCallback : PageClick
										});
									}
								}
								if (typeof data.page == 'undefined') {
									for (var k = 0; k < 10; k++) {
										var tr = $("<tr></tr>");
										$("<td colspan='9'>&nbsp;</td>")
												.appendTo($(tr));
										$(tr).appendTo($("#tabelid"));
										$("#tabelid tr:odd")
												.addClass("bgWhite");
										$("#total").text(0);
										$("#pager").pager({
											pagenumber : pageclickednumber,
											pagecount : 0,
											buttonClickCallback : PageClick
										});
									}
								}

							});
		};

		var pageCount = 0;
		$(function() {

			if (pageCount == 0) {
				//页面加载时判断加载的页数
				if("${requestScope.flag }" == "succ"){
					PageClick(${requestScope.pageCounts });
					return;
				}
				
				PageClick(1);
			}
			//--------------------------
			//应用按钮
			//--------------------------

			$('.btn').click(function() {

				PageClick(1);
			});

		});
		
		function deleteModel(){
			if(confirm('您确定删除吗？')) {
				return true;
			}else{
				return false;
			}
		}
		
		function queryclass(){
			PageClick(1);
		}
		

		
	</script>
</body>
</html>